import Vue from 'vue'
import Vuex, { Store } from 'vuex'
import createPersistedState from 'vuex-persistedstate'


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: {
      name:'小李锅',
      date:'15',
      email:'2336936131@qq.com',
      sex:'男',
      student:'学生',
      area:'贵阳',
    },
    experience:{
      schoolName:'Vue大学',
      inrollmentYear:'2021',
      graduationYear:'2025',
      profession:'计算机技术',
      education:'本科',
    },
    form:{
      career:'JAVA',
      attribute:'全职',
      minSalary:'5k',
      maxSalary:'10k',
      area:'贵阳',
      status:'离职',
      dutyTime:'随时',
    },
  },
  getters: {
    currentUser: state => state.user
  },
  mutations: {
    UPDATA_USER(state,newUser){
      state.user = {...state.user,...newUser}
    },
    UPDATA_EXPERIENCE(state,newExperience){
      state.experience = {...state.experience,...newExperience}
    },
    UPDATA_FORM(state,newForm){
      state.form = {...state.form,...newForm}
    },
    CLEAR_MESSAGE(state){
      state.user = {}
      state.experience = {}
      state.form = {}
      localStorage.removeItem('vuex')

    }
  },
  actions: {
    updataUser({commit},newUser){
      commit('UPDATA_USER',newUser)
    },
    updataExperience({commit},newExperience){
      commit('UPDATA_EXPERIENCE',newExperience)
    },
    updataForm({commit},newForm){
      commit('UPDATA_FORM',newForm)
    },
    clearMessage({commit}){
      commit('CLEAR_MESSAGE')
    }
  },
  plugins: [createPersistedState()],
  modules: {
  }
})
